package com.sfh.cp.home.child.adapter;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sfh.cp.R;
import com.sfh.cp.widget.IContentOnClickLayout;
import com.sfh.cp.widget.WidgetContentImageLayout;
import com.sfh.cp.widget.WidgetContentPersonLayout;
import com.sfh.cp.widget.WidgetContentTextLayout;
import com.sfh.cp.widget.WidgetUserTopLayout;

import java.util.ArrayList;

import crm.sfh.server.entity.EContent;

/**
 * 内容适配器
 */

public class ContentAdapter extends BaseMultiItemQuickAdapter<EContent, BaseViewHolder> {
    IContentOnClickLayout  onClickLayout;

    public ContentAdapter(IContentOnClickLayout onClickLayout) {
        super(new ArrayList<EContent>(0));
        this.onClickLayout = onClickLayout;
        addItemType(EContent.TEXT, R.layout.home_child_text_recycle_item);
        addItemType(EContent.IMG, R.layout.home_child_image_recycle_item);

    }

    @Override
    protected void convert(BaseViewHolder helper, EContent item) {
        WidgetUserTopLayout userTopLayout= helper.getView(R.id.lyUser);
        userTopLayout.showData(item.getPerson());
        userTopLayout.showTime(item.getContentType().getCreateTime());
        WidgetContentPersonLayout personLayout =  helper.getView(R.id.lyPerson);
        personLayout.setOnClickMessage(onClickLayout);
        userTopLayout.setOnClickUser(onClickLayout);

        switch (item.getItemType()) {
            case EContent.IMG:
                WidgetContentImageLayout contentImageLayout =  helper.getView(R.id.lyContent);
                contentImageLayout.showData(item.getContentType());
                personLayout.setData(item);
                contentImageLayout.setOnClickLayout (onClickLayout);
                break;
            case EContent.TEXT:

                WidgetContentTextLayout contentTextLayout =  helper.getView(R.id.lyContent);
                contentTextLayout.setData(item.getContentType());
                personLayout.setData(item);
                contentTextLayout.setOnClickLayout (onClickLayout);
                break;
            default:
                break;
        }

    }


}
